package ext.tianma.part.finishedProduct.datautilities;

import java.util.HashMap;
import java.util.Map;

import wt.util.WTException;

import com.ptc.core.components.descriptor.ModelContext;
import com.ptc.core.components.factory.dataUtilities.DefaultDataUtility;
import com.ptc.core.components.rendering.PickerRenderConfigs;
import com.ptc.core.components.rendering.guicomponents.PickerInputComponent;


public class UserPickDataUtility extends DefaultDataUtility{

	@Override
	public Object getDataValue(String paramString, Object obj, ModelContext modelContext) throws WTException {
		
	   return newUserPicker(paramString,null,false);
	}

	private PickerInputComponent newUserPicker(String columnId, String defautValue, boolean required) throws WTException {
    	Map prop = new HashMap<String, String>();
		PickerRenderConfigs.setDefaultPickerProperty(prop, PickerRenderConfigs.PICKER_CALLBACK, "PickerInputComponentCallback");
		PickerRenderConfigs.setDefaultPickerProperty(prop, PickerRenderConfigs.INCLUDE_TII, "true");
		PickerRenderConfigs.setDefaultPickerProperty(prop, PickerRenderConfigs.PICKER_ID, columnId+"_reviewer");
		PickerRenderConfigs.setDefaultPickerProperty(prop, PickerRenderConfigs.HIDDEN_ID, columnId);
		PickerRenderConfigs.setDefaultPickerProperty(prop, PickerRenderConfigs.OBJECT_TYPE, "wt.org.WTUser");
		PickerRenderConfigs.setDefaultPickerProperty(prop, PickerRenderConfigs.READ_ONLY_TEXTBOX, "true");
		PickerRenderConfigs.setDefaultPickerProperty(prop, PickerRenderConfigs.SHOW_SUGGESTION, "true");
		PickerRenderConfigs.setDefaultPickerProperty(prop, PickerRenderConfigs.SUGGEST_SERVICE_KEY, "userPicker");
		PickerRenderConfigs.setDefaultPickerProperty(prop, PickerRenderConfigs.PICKER_ATTRIBUTES, "fullName");
		PickerRenderConfigs.setDefaultPickerProperty(prop, PickerRenderConfigs.SHOW_CLEAR_ACTION, "true");
		if (defautValue != null) {
			PickerRenderConfigs.setDefaultPickerProperty(prop, "defaultValue", defautValue);
		}
		PickerInputComponent pic = new PickerInputComponent("", "", PickerRenderConfigs.getPickerConfigs(prop), 20);
		pic.setName(columnId+"_name");
		pic.setColumnName(columnId+"_name");
		pic.setSearchDisplayId(columnId+"_search");
		pic.setRequired(required);
		return pic;
    }
}
